#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
int msg[1];
RF24 radio(40,53);
const uint64_t pipe = 0xE8E8F0F0E1LL;

#define trigPin 13
#define echoPin 12
#define led 11
#define led2 10

void setup() {
  Serial.begin (9600);
  radio.begin();
  radio.openWritingPipe(pipe);}
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(14, LOW);
  pinMode(15, OUTPUT):
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 10) {  // This is where the LED On/Off happens
    radio.write(msg, 1);
    Serial.write(msg);
    digitalWrite(15, HIGH);
    delay(1000);
    digitalWrite(15, LOW):
    delay(1000):
    digitalWrite(15, HIGH);
    
    
}
  else {
    
  }
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
    digitalWrite(15, LOW):
    
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}
